<?php

namespace App\Http\Controllers;


use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use App\Tools\Func;
use Illuminate\Support\Facades\DB;

use App\Models\KeShi;
use App\Models\Yisheng;

class KeshiController extends Controller
{
    use Func; 

    public function keshi(Request $request)
    {
       $keywords = trim($request->keywords);
       
       $data = KeShi::where(function ($query) use($keywords) {
           // 关键字
           if ($keywords) {
               $query->orWhere('keshi_name', $keywords);
           }
       })->get();

       return $this->returnJson(0, 'success', $data);
    }   
	
	public function yisheng(Request $request)
	{
	    $keywords = trim($request->keywords);
		$keshi_id = trim($request->keshi_id);
	    $data = Yisheng::with('keshi')->where(function ($query) use($keywords, $keshi_id) {
	        // 关键字
	        if ($keywords) {
	            $query->orWhere('yisheng_name', 'like', '%'.$keywords.'%');
	        }
			if ($keshi_id) {
			    $query->orWhere('keshi_id', $keshi_id);
			}
	    })->get();
	    return $this->returnJson(0, 'success', $data);
	}
	
	public function yishengInfo(Request $request)
	{
	    $data = Yisheng::with('keshi')->where('id', $request->id)->first();
	    return $this->returnJson(0, 'success', $data);
	}

}
